using System;
using System.Collections.Generic;
using System.Text;


namespace TaugeLibrary.Classes
{
    public class SqlConnectionData
    {
        #region memvar
        private string m_svr;
        private string m_db;
        private string m_usr;
        private string m_hpwd;
        private bool m_auth;
        #endregion

        #region properties
        public string DBServer
        {
            get { return m_svr; }
            set { m_svr = value; }
        }

        public string DBName
        {
            get { return m_db; }
            set { m_db = value; }
        }

        public string DBUser
        {
            get { return m_usr; }
            set { m_usr = value; }
        }

        public string DBPasswordHashed
        {
            get { return m_hpwd; }
            set { m_hpwd = value; }
        }

        
        public string DBPassword
        {
            get { return m_hpwd; } // TaugeEncryption.hrDecrypt(m_hpwd, FwConstants.ENC_KEY); }
            set { m_hpwd = value; } // TaugeEncryption.hrEncrypt(value, FwConstants.ENC_KEY); }
        }
        

        public bool DBAuth
        {
            get { return m_auth; }
            set { m_auth = value; }
        }
        #endregion

        #region Constructor
        public SqlConnectionData(string p_server, string p_db, string p_user, string p_hpwd, bool p_auth)
        {
            DBServer = p_server;
            DBName = p_db;
            DBUser = p_user;
            DBPassword = p_hpwd;
            DBAuth = p_auth;
        }
        public SqlConnectionData()
            : this(".", "master", "sa", "", true)
        {
        }

        #endregion

        #region methods
        public string getConnectionString()
        {
            if (DBAuth)
                return "server=" + DBServer + ";database=" + DBName + ";Trusted_Connection=Yes;Pooling=True;Max Pool Size=100;";
            else
                return "server=" + DBServer + ";database=" + DBName + ";user id=" + DBUser + ";pwd=" + DBPassword + ";Trusted_Connection=No;Pooling=True;Max Pool Size=100;";
        }

        public string getConnectionStringADODB()
        {
            if (DBAuth)
                return "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" + DBName + ";Data Source=" + DBServer;
            else
                return "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=" + DBName + ";Data Source=" + DBServer + ";User ID=" + DBUser + ";password=" + DBPassword + ";";

        }


        #endregion

    }
}
